import {createRouter, createWebHashHistory, RouteRecordRaw} from 'vue-router'
import {i18n} from '@/i18n'

// @ts-ignore
export const menuRoutes: RouteRecordRaw[] = [
    {
        path: '/gen/dict',
        name: 'dict',
        component: () => import('../views/dict/index.vue'),
        meta: {
            title: '代码生成器',
            icon: 'icon-detail'
        }

    }, {
        path: '/gen/gen',
        name: 'gen',
        component: () => import('../views/generator/index.vue'),
        meta: {
            title: '代码生成器NEW',
            icon: 'icon-detail'
        }
    }, {
        path: '/uiModel/uiModel',
        name: 'uiModel',
        component: () => import('../views/uiModel/uiModel.vue'),
        meta: {
            title: 'UI model',
            icon: 'icon-detail'
        }
    },
]

export const constantRoutes: RouteRecordRaw[] = [
    {
        path: '/redirect',
        component: () => import('../layout/index.vue'),
        children: [
            {
                path: '/redirect/:path(.*)',
                component: () => import('../layout/components/Router/Redirect.vue')
            }
        ]
    },
    {
        path: '/',
        component: () => import('../layout/index.vue'),
        // redirect: '/home',
        redirect: '/homePage', // 重定向至UI Model
        children: [
            {
                path: '/home',
                name: 'Home',
                component: () => import('../views/home.vue'),
                meta: {
                    title: i18n.global.t('router.home'),
                    affix: true
                }
            },
            ...menuRoutes
        ]
    },
    {
        path: '/homePage',
        component: () => import('../views/homePage/homePage.vue')
    },
    {
        path: '/uiModel',
        component: () => import('../views/uiModel/uiModel.vue')
    },
    {
        path: '/404',
        component: () => import('../views/404.vue')
    },
    {
        path: '/:pathMatch(.*)',
        redirect: '/404'
    }
]

export const router = createRouter({
    history: createWebHashHistory(),
    routes: constantRoutes
})
